﻿Partial Class Registro_ubicaciones
    Inherits System.Web.UI.Page


    Protected Sub btnMover_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMover.Click
        Dim sNuevaUbicacion As String = ddlDestino.SelectedValue 'Obten la nueva ubicacion
        Dim sIndice As String ' Determina de que corral se moveran se moveran los registros
        Dim gvCorral As New GridView

        If sNuevaUbicacion.Length = 3 Then
            ' Determina cual es la zona activa que deseo trabajar
            If rbActivo1.Checked Then
                sIndice = "1"
                gvCorral = gvCorral1
            ElseIf rbActivo2.Checked Then
                sIndice = "2"
                gvCorral = gvCorral2
            ElseIf rbActivo3.Checked Then
                sIndice = "3"
                gvCorral = gvCorral3
            ElseIf rbActivo4.Checked Then
                sIndice = "4"
                gvCorral = gvCorral4
            Else
                Exit Sub
            End If

            ' Por cada registro verifica si está seleccionado
            For Each row In gvCorral.Rows
                Dim chk As CheckBox = row.FindControl("chkItemSelect" + sIndice)
                If chk IsNot Nothing AndAlso chk.Checked Then 'Si está seleccionado obten el id del Animal
                    Dim IdAnimal As Integer = Convert.ToInt32(gvCorral.DataKeys(row.RowIndex).Value)
                End If
            Next
        Else
            lblError.Text = "Selecciona una ubicación"
        End If





        'Dim respuesta As String
        'respuesta = ""
        'For Each row In gvCorral.Rows
        '    Dim cb As CheckBox = row.FindControl("chkItemSelect" + sIndice)
        '    If cb IsNot Nothing AndAlso cb.Checked Then
        '        Dim productID As Integer = Convert.ToInt32(gvCorral.DataKeys(row.RowIndex).Value)
        '        respuesta = respuesta + "Id: " + productID.ToString + " Ubica: " _
        '                    + ddlDestino.SelectedValue + "<br>"
        '    End If
        'Next


        'lblError.Text = respuesta




    End Sub




#Region "Seleccionar todo"
    Protected Sub chkSelectAll1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim rbActivo As Boolean = False
        Dim chkSeleccionado As CheckBox = gvCorral1.HeaderRow.FindControl("chkSelectAll1")
        For Each row In gvCorral1.Rows
            Dim chk As CheckBox = row.FindControl("chkItemSelect1")
            chk.Checked = chkSeleccionado.Checked
            If chk.Checked Then
                rbActivo = True
            End If
        Next
        rbActivo1.Checked = rbActivo
    End Sub

    Protected Sub chkSelectAll2_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim rbActivo As Boolean = False
        Dim chkSeleccionado As CheckBox = gvCorral2.HeaderRow.FindControl("chkSelectAll2")
        For Each row In gvCorral2.Rows
            Dim chk As CheckBox = row.FindControl("chkItemSelect2")
            chk.Checked = chkSeleccionado.Checked
            If chk.Checked Then
                rbActivo = True
            End If
        Next
        rbActivo2.Checked = rbActivo
    End Sub
    Protected Sub chkSelectAll3_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim rbActivo As Boolean = False
        Dim chkSeleccionado As CheckBox = gvCorral3.HeaderRow.FindControl("chkSelectAll3")
        For Each row In gvCorral3.Rows
            Dim chk As CheckBox = row.FindControl("chkItemSelect3")
            chk.Checked = chkSeleccionado.Checked
            If chk.Checked Then
                rbActivo = True
            End If
        Next
        rbActivo3.Checked = rbActivo
    End Sub
    Protected Sub chkSelectAll4_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim rbActivo As Boolean = False
        Dim chkSeleccionado As CheckBox = gvCorral4.HeaderRow.FindControl("chkSelectAll4")
        For Each row In gvCorral4.Rows
            Dim chk As CheckBox = row.FindControl("chkItemSelect4")
            chk.Checked = chkSeleccionado.Checked
            If chk.Checked Then
                rbActivo = True
            End If
        Next
        rbActivo4.Checked = rbActivo
    End Sub
#End Region
#Region "Seleccion de area activa"
    Protected Sub chkItemSelect1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim rbActivo As Boolean = False
        For Each row In gvCorral1.Rows
            Dim cb As CheckBox = row.FindControl("chkItemSelect1")
            If cb.Checked Then
                rbActivo = True
            End If
        Next
        rbActivo1.Checked = rbActivo
    End Sub
    Protected Sub chkItemSelect2_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim rbActivo As Boolean = False
        For Each row In gvCorral2.Rows
            Dim cb As CheckBox = row.FindControl("chkItemSelect2")
            If cb.Checked Then
                rbActivo = True
            End If
        Next
        rbActivo2.Checked = rbActivo
    End Sub
    Protected Sub chkItemSelect3_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim rbActivo As Boolean = False
        For Each row In gvCorral3.Rows
            Dim cb As CheckBox = row.FindControl("chkItemSelect3")
            If cb.Checked Then
                rbActivo = True
            End If
        Next
        rbActivo3.Checked = rbActivo
    End Sub
    Protected Sub chkItemSelect4_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim rbActivo As Boolean = False
        For Each row In gvCorral4.Rows
            Dim cb As CheckBox = row.FindControl("chkItemSelect4")
            If cb.Checked Then
                rbActivo = True
            End If
        Next
        rbActivo4.Checked = rbActivo
    End Sub
#End Region
#Region "Actualizar al modificar registro"
    Protected Sub Actualizar()
        gvCorral1.DataBind()
        gvCorral2.DataBind()
        gvCorral3.DataBind()
        gvCorral4.DataBind()
        rbActivo1.Checked = False
        rbActivo2.Checked = False
        rbActivo3.Checked = False
        rbActivo4.Checked = False
    End Sub
    Protected Sub gvCorral1_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles gvCorral1.RowUpdated
        Call Actualizar()
    End Sub
    Protected Sub gvCorral2_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles gvCorral2.RowUpdated
        Call Actualizar()
    End Sub
    Protected Sub gvCorral3_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles gvCorral3.RowUpdated
        Call Actualizar()
    End Sub
    Protected Sub gvCorral4_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles gvCorral4.RowUpdated
        Call Actualizar()
    End Sub
#End Region
End Class
